package ed.hbut.supermarket1.controller;

import ed.hbut.supermarket1.dto.FinanceDto;
import ed.hbut.supermarket1.entity.Cost;
import ed.hbut.supermarket1.entity.Result;
import ed.hbut.supermarket1.service.FinanceService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@Slf4j
@RestController
public class FinanceController {


    @Autowired
    private FinanceService financeService;

    /**
     * 查询销售额
     * @param
     * @return
     */
    @GetMapping("/api/financial/sales")
    public Result financial(@RequestParam Integer year,
                            @RequestParam(required = false) Integer month) {
        log.info("年份={}, 月份={}", year, month);

        List<FinanceDto> price= financeService.getSalePrice(year,month);

         log.info("总价为={}", price);
            log.info(Result.success(price).toString());
        return Result.success(price);

    }

    /**
     * 查询成本
     */
    @GetMapping("/api/financial/cost")
    public Result getCost(@RequestParam Integer year,
                          @RequestParam(required = false) Integer month) {

        List<FinanceDto> cost=financeService.getCost(year,month);
        log.info("总成本为：={}", cost);

        return  Result.success(cost);
    }

    /**
     * 获取成本列表
     */
    @GetMapping("/api/cost")
    public Result getCostList(){

        List<Cost> list=  financeService.getCostList();
        return Result.success(list);
    }




}
